$(function () {
    $('#signin-btn').click(function (evevt) {
        evevt.preventDefault();
        var telephoneInput = $('input[name="telephone"]');
        var passwordInput = $('input[name="password"]');
        var rememberInput = $('input[name="remember"]');

        var telephone = telephoneInput.val();
        var password = passwordInput.val();
        var remember = rememberInput.checked?1:0;

        zlajax.post({
            'url':'/signin/',
            'data':{
                'telephone':telephone,
                'password':password,
                'remember':remember
            },
            'success':function (data) {
                if (data['code']== 200){
                    var return_to = $('#return-to-span').text();
                    if(return_to){
                        if(return_to == '/signup/'){
                            window.location = '/'
                        }
                        else {
                            window.location = return_to;
                        }

                    }else {
                        window.location = '/';
                    }
                }else {
                    xtalert.alertInfo(data['message'])
                }
            },
            'fail':function () {
                xtalert.alertNetworkError()
            }
        })
    })
});